﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using System.Windows.Controls.Primitives;

namespace EnsureWeb.Controls
{
    public class DialogPanel : ContentControl
    {       
        public DialogPanel(): base()
        {
            this.DefaultStyleKey = typeof(DialogPanel);           
        }

        public override void OnApplyTemplate()
        { 
            base.OnApplyTemplate();

            ButtonBase bgButton = this.GetTemplateChild("bgButton") as ButtonBase;
            bgButton.Click += new RoutedEventHandler(bgButton_Click);

            ButtonBase close = this.GetTemplateChild("close") as ButtonBase;
            close.Click += new RoutedEventHandler(close_Click);
        }

        void bgButton_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        void close_Click(object sender, RoutedEventArgs e)
        {
            this.Hide();
        }

        public void Show()
        {
            this.Visibility = Visibility.Visible;
        }
        
        public void Hide()
        {
            this.Focus();
            
            if (this.OnClose != null)
                OnClose(this, null);

            this.Visibility = Visibility.Collapsed;
        }
        
        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(object), typeof(DialogPanel), null);
        public object Title
        {
            get { return (object)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); } 
        }

        public event RoutedEventHandler OnClose;
    }
}
